<template>
  <div>
    <el-dialog
      title="任务记录列表"
      :visible="dialogVisible"
      custom-class="custom-dialog"
      :before-close="handleClose"
      @open="initData"
      width="78%"
      class="dialogClass"
    >
      <div class="page-container">
        <SearchPanel @change="handleSearchPanelChange">
          <el-form
            ref="queryForm"
            class="query-more-form"
            size="mini"
            label-width="100px"
            :model="query"
          >
            <el-row :gutter="24">
              <el-col :span="16">
                <el-form-item label="综合条件">
                  <el-input
                    v-model="query.query"
                    class="search-ipt"
                    placeholder="请输入查询条件"
                    maxlength="255"
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item label="行业" prop="industry">
                  <el-select
                    class="form_industry"
                    v-model="query.industry"
                    placeholder="请选择行业"
                    @change="changeIndustryCode"
                  >
                    <el-option
                      v-for="item in industryArr"
                      :key="item.id"
                      :label="item.name"
                      :value="item.code"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="时间区间">
                  <el-date-picker
                    v-model="query.caseTime"
                    type="datetimerange"
                    range-separator="-"
                    start-placeholder="开始"
                    end-placeholder="结束"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col> -->
              <el-col :span="6">
                <el-button size="mini" class="search-btn" @click="select"
                  >查询</el-button
                >
                <el-button
                  size="mini"
                  class="search-btn"
                  @click="resetForm('queryForm')"
                  >重置</el-button
                >
              </el-col>
            </el-row>
          </el-form>
        </SearchPanel>
        <div class="table-container">
          <!-- <div class="table-tools-panel table-flex-row">
            <div class="table-btns-left">
              <el-button
                class="flush-btn blue"
                icon="el-icon-plus"
                @click="addCust"
                >新增</el-button
              >
              <el-button
                class="flush-btn yellow"
                icon="el-icon-refresh"
                @click="refresh"
                >刷新</el-button
              >
            </div>
            <div>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-set-up"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-share"
              ></el-button>
              <el-button
                class="tools-btn"
                size="mini"
                icon="el-icon-printer"
              ></el-button>
            </div>
          </div> -->
          <div class="table-list-panel">
            <el-table
              v-loading="tableLoading"
              border
              size="small"
              :data="tableData"
              :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
              style="width: 100%"
            >
              <el-table-column type="selection" width="45" />
              <el-table-column
            prop="unitName"
            label="巡查对象名称"
            show-overflow-tooltip
          />
           <el-table-column
            prop="categoryCompleteName"
            label="检查事项全称"
            show-overflow-tooltip
          />
          <el-table-column prop="startTime" label="巡检时间区间" width="260">
            <template slot-scope="scope">
              <div>
                {{ parseTime(scope.row.beginTime) }}~{{
                  parseTime(scope.row.endTime)
                }}
              </div></template
            >
          </el-table-column>
         
          <el-table-column
            prop="deptName"
            label="检查部门"
            show-overflow-tooltip
          />
          <el-table-column
            prop="patrolUserNumber"
            label="执法人员数"
            width="100"
            show-overflow-tooltip
          />
           <el-table-column
            prop="planNumber"
            label="计划巡检次数"
            width="100"
            show-overflow-tooltip
          />
          <el-table-column
            prop="completeNumber"
            label="实际完成次数"
            width="100"
            show-overflow-tooltip
          />
          <el-table-column prop="status" label="完成情况" show-overflow-tooltip>
            <template slot-scope="scope">
              <template v-if="scope.row.status == 0">
                <span>未完成</span>
              </template>
              <template v-if="scope.row.status == 1">
                <span>已完成</span>
              </template>
            </template>
          </el-table-column>
              <el-table-column label="操作" width="120">
                <template slot-scope="scope">
                  <el-button
                    class="table-inner-btn"
                    type="text"
                    size="mini"
                    @click="handDetail(scope.row)"
                    >详情</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination-panel">
            <Pagination
              :total="query.total"
              :page.sync="query.pageNum"
              :limit.sync="query.pageSize"
              @pagination="select"
            />
          </div>
        </div>

        <!-- <InspectionItemDetailsDialog
          :dialogVisible="DetailsDialog"
          :caseId="caseId"
          @closeDialog="DetailsDialog = false"
        /> -->
      </div>
    </el-dialog>
    <DetailsDialog
      :dialogVisible="DetailsDialog"
      :caseId="caseId"
      @closeDialog="DetailsDialog = false"
    />
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import CustomDialog from "./CustomDialog";
import DetailsCustomDialog from "./DetailsCustomDialog";
import DetailsDialog from "./DetailsDialog";
import { parseTime } from "@/utils/index";
import { sourceType, industryArea } from "@/api/case";
import { getList1 } from "@/api/system/inspectionItemRecord";
import {
  getList,
  getPatrolList,
  editPlan
} from "@/api/system/doubleRandomMatters";
export default {
  name: "SpecialMatters",
  components: {
    SearchPanel,
    Pagination,
    CustomDialog,
    DetailsCustomDialog,
    DetailsDialog
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    taskId: {
      type: Number,
      default: null
    },
    reportList: {
      type: Array,
      default: () => {}
    }
  },
  watch: {
    reportList(val) {
      this.tableData = val;
      this.query.total = val.length;
    }
  },
  data() {
    return {
      query: {
        total: 1,
        pageNum: 1,
        pageSize: 10,
        type: 0,
        caseTime: []
      },
      tableLoading: false,
      DetailsCustomDialog: false,
      DetailsDialog: false,
      tableData: [],
      department: [],
      isShow: true,
      visible: false,
      dialogType: "detail",
      // 行业类型
      industryArr: [],
      obj: {},
      caseId: null
    };
  },
  created() {
    this.initData();
    this.changeIndustryId();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    handleClose() {
      this.$emit("closeDialog");
    },

    resetForm(queryForm) {
      // this.$refs[queryForm].resetFields();
      this.query.query = "";
    },
    changeEnable(val) {
      editPlan({
        id: val.id,
        enable: val.enable == true ? 0 : 1
      })
        .then(() => {
          this.$message.success("修改成功");
        })
        .catch(() => {});
    },

    // 查询行业
    changeIndustryId() {
      sourceType({
        parentCode: 0,
        typeCode: 2
      }).then(result => {
        let { code, rows } = result;
        if (code == 200) {
          this.industryArr = rows;
        }
      });
    },
    // 选择行业
    changeIndustryCode(val) {
      this.industryArr.forEach(item => {
        if (val == item.code) {
          this.query.primaryCategoryName = item.name;
          this.query.primaryCategoryId = item.id;
        }
      });
    },
    parseTime,
    select() {
      // if (this.query.caseTime) {
      //   this.query.startTime = new Date(this.query.caseTime[0]).getTime();
      //   this.query.endTime = new Date(this.query.caseTime[1]).getTime();
      // }
      // let isUserDataMsg = JSON.parse(localStorage.getItem("isUserDataMsg"));
      // this.query.deptId = isUserDataMsg.deptId;
      // const query = JSON.parse(JSON.stringify(this.query));
      // this.tableLoading = true;
      // getPatrolList(query)
      //   .then(result => {
      //     this.tableLoading = false;
      //     // this.query.total = result.total;
      //     // this.tableData = result.rows;
      //     // this.tableData.forEach(item => {
      //     //   item.enable = item.enable == 0 ? true : false;
      //     // });
      //   })
      //   .catch(() => {
      //     this.tableLoading = false;
      //   });
    },
    // 新增成功，刷新页面
    refreshData() {
      this.select();
    },
    // 刷新页面
    refresh() {
      this.query = {
        total: 1,
        pageNum: 1,
        pageSize: 10,
        type: 0
      };
      this.select();
    },
    // 新增
    addCust() {
      this.visible = true;
      this.dialogType = "add";
      this.obj = {};
    },
    // 详情
    handDetail(row) {
      this.DetailsDialog = true;
      this.caseId = row.id;
      // getOne(row.id).then(res => {
      //   this.dialogType = "detail";
      //   this.DetailsCustomDialog = true;
      //   this.obj = JSON.parse(JSON.stringify(res.data));
      // });
    }
  }
};
</script>
<style lang="scss" scoped>
.el-input__inner {
  width: auto;
}
</style>
